﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Hospital.Models;

namespace Hospital.Controllers
{
    public class ZaprosController : Controller
    {
         private DataManager _dataManager;

        public ZaprosController(DataManager dataManager)
        {
            _dataManager = dataManager;
        }

        public ActionResult List()
        {
            ViewData["Title"] = "Список заявок";
            ViewData["Zap"] = _dataManager.zap.GetZapros();
            return View();
        }

        [Authorize(Roles = "Doc")]
        public ActionResult OneZap(int id)
        {
            ViewData.Model = _dataManager.zap.GetOneZapros(id);
            return View();
        }

        [Authorize(Roles = "Doc")]
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult Edit(int id)
        {
            Zapro z = _dataManager.zap.GetOneZapros(id);
            ViewData.Model = z;

            SetEditList(z);
            return View();                        
        }

        private void SetEditList(Zapro z)
        {
            ViewData["Bol"] = new SelectList(_dataManager.spr.GetSpravki(), "Id_Bol", "Symptom", z.Spr_Id);
        
        }

        [Authorize(Roles = "Doc")]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(int id, Zapro z)
        {

            if (ModelState.IsValid)
            {
                z.Id_Zap = id;
                _dataManager.zap.UpdateZapros(z);
                return RedirectToAction("List");
            }
            SetEditList(z);
            return View();
        }


        [Authorize(Roles = "Doc")]
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult EditVip(int id)
        {
            return View();
        }

        [Authorize(Roles = "Doc")]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult EditVip(int id, Zapro z)
        {

            if (ModelState.IsValid)
            {
                z.Id_Zap = id;
                _dataManager.zap.UpdateZaprosDoc(z);
                return RedirectToAction("List");
            }
            SetEditList(z);
            return View();
        }

    }
}
